package demo9;

/**
 */


import java.util.*;
public class Main3 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while(sc.hasNext()){
            int n = sc.nextInt();
            Card[] cards = new Card[n];
            for (int i = 0; i < n; i++) {
                int x = sc.nextInt();
                int y = sc.nextInt();
                cards[i] = new Card(x,y);
            }
            Arrays.sort(cards);
            int[] num = new int[n];

            int p = 0;
            for (Card e : cards){
                num[p++] = e.w;
            }
            System.out.println(lengthOfLIS(num));
        }
    }

    public static int lengthOfLIS(int[] nums) {

        if(nums.length == 0) return 0;

        int n = nums.length;
        int[] dp = new int[n];
        dp[0] = 1;
        int res = dp[0];
        for (int i = 1; i < n ; i++) {
            dp[i] = 1;
            for (int j = 0; j < i; j++) {
                if(nums[i] > nums[j]){
                    dp[i] = Math.max(dp[i],dp[j]+1);
                }
            }
            res = Math.max(res,dp[i]);
        }
        return res;
    }
}


class Card implements Comparable{

    Integer h;
    Integer w;

    Card(Integer h,Integer w){
        this.h = h;
        this.w = w;
    }

    @Override
    public int compareTo(Object o) {
        if(o instanceof Card){
            Card p = (Card)o;
            int res = this.h.compareTo(p.h);
            if(res == 0){
                return this.w.compareTo(p.w);
            } else{
                return res;  // 当两者的val相等时,直接返回0,即按照先后顺序排序
            }
        }
        return 0;
    }
}